<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <link rel="stylesheet" href="styles/style.css">
        <link rel="stylesheet" href="styles/theme/atom-one-dark.css">
        <title>例子8-JS进阶（三）</title>
    </head>
    <body>
        <pre>
            <code>
                    // 例子8

                    var myPromise =  new Promise(function(resolve, reject) {
                        var random = Math.random();
                        if (random >= 0.5) {
                                resolve('访问成功！');
                        } else {
                                reject('访问失败！');
                        }
                    });

                    myPromise.then(function(value) {
                            console.log(value);
                            return value;
                    }).catch(function(err) {
                            console.log(err);
                            return err;
                    }).finally(function() {
                            console.log('over!');
                    });
            </code>
        </pre>
        <script src="scripts/libs/highlight.pack.js"></script>
        <script src="scripts/8.js"></script>
        <script>
            hljs.initHighlightingOnLoad();
        </script>
    </body>
</html>